package com.iot.ic.common.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.iot.ic.modules.model.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class LoginInterceptor extends HandlerInterceptorAdapter {
	private List<String> excludeURIs;

	/**
	 * 1.登录拦截， 2.session过期拦截 3.用户权限拦截
	 */
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String requestURI = request.getServletPath();
		return true;
//		if (Utils.isEmpty(requestURI)) {
//			return super.preHandle(request, response, handler);
//		}
//		if (excludeURIs != null && !excludeURIs.isEmpty()) {// 不拦截的
//			for (String url : excludeURIs) {
//				if (requestURI.contains(url))
//					return super.preHandle(request, response, handler);
//			}
//		}
//		HttpSession s = request.getSession();
//		User user = (User) s.getAttribute(Constants.LOGIN_KEY);
//		if (user != null) {// 已登陆
//			if(authIsRight(requestURI,user,request,response)){
//				return super.preHandle(request, response, handler);
//			}else{
//				response.setContentType("text/html;charset=UTF-8");
//				response.getWriter().write(
//						"<script>history.back(-1) ;"
//								+ "alert('当前登录用户无权操作！');</script>");
//				return false;
//			}
//		} else {
//			String loginUrl = request.getContextPath();
//			loginUrl += "/login.html";
//			response.sendRedirect(loginUrl);
//		}
//		return false;
	}


	/**
	 * 判断用户是否被删除
	 * @param user
	 * @return
	 */
	public boolean isDel(User user) {
		if (user.getDelStatus()!=0) {
			return false;
		}
		return true;
	}

	// ********************************get(),set()************************/

	public List<String> getExcludeURIs() {
		return excludeURIs;
	}

	public void setExcludeURIs(List<String> excludeURIs) {
		this.excludeURIs = excludeURIs;
	}


}
